﻿/***
    Copyright 2012 Stijn Van Antwerpen

    This file is part of Qasparov.

    Qasparov is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Qasparov is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Qasparov. If not, see <http://www.gnu.org/licenses/>.

 */


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Qbus.Communication;
using System.Threading;

namespace QBusAPIGenerator
{
    class Program
    {
        static void Main(string[] args)
        {

            Controller controller = new Controller();

            controller.Address = Read("QBus address (192.168.1.1 or myqbus.mydomain)");
            controller.Login = Read("QBus login");
            controller.Password = Read("QBus Pasword (not stored)");

            Console.WriteLine("Connecting...");

            ConnectionManager.Instance.Connect(controller);

            Thread.Sleep(2000);
            Console.WriteLine("Connected.");

            Console.WriteLine("Loadling modules and Presets");
            ConnectionManager.Instance.Modules.GetModulesAsync();
            ConnectionManager.Instance.Presets.GetPresetsAsync();

            Thread.Sleep(2000);
            Console.WriteLine("Loaded {0} modules", controller.Modules.Count);
            Console.WriteLine("Loaded {0} presets", controller.Presets.Count);

            var namespaceName = Read("Namespace");
            var className = Read("Class Name");
            Console.WriteLine("Generating code file {0}.cs", className);

            QBusAPIGenerator qb = new QBusAPIGenerator(namespaceName, className, controller);

            qb.Generate();

            Console.WriteLine("Done.");
            Console.ReadLine();
            
        }

        static String Read(String text)
        {
            Console.Write(String.Format("{0}: ", text));
            return Console.ReadLine();
        }
    }
}
